#ifndef _APP_H_
#define _APP_H_
#include "stm32l0xx_hal.h"

#define AXIS_BUFFER_SIZE   200

#define OTA_RESET_MANAGER_ENABLE   0x01

#define CRC_OK     0x01
#define CRC_ERROR  0x00

#define OTA_WRITE_FLASH_PAGE_NUMBER  1
#define OTA_WRITE_FLASH_WORD_NUMBER  OTA_WRITE_FLASH_PAGE_NUMBER * 32
#define OTA_WRITE_FLASH_BYTE_NUMBER  OTA_WRITE_FLASH_WORD_NUMBER * 4
#define OTA_CRC_BYTE_NUMBER    128


typedef struct _Axis_type_t{
 int16_t axis_x;
 int16_t axis_y;
 int16_t axis_z;
}axis_type_t;

typedef struct _Axis_average_value_t{
 int32_t average_x;
 int32_t average_y;
 int32_t average_z;
}axis_average_value_t;

typedef struct _Adv_manufactory_data_t{
 uint8_t  len;
 uint8_t  adv_type;
 uint8_t  company_id[2];
 uint8_t  data_type[2];
 uint8_t  data[];
} adv_manufactory_data_t;

/*OTA*/
typedef struct _flash_write_info_t{
  uint32_t address;
  uint8_t  size;

} flash_write_info_t;

typedef enum {
 app_ok = 0x00,
 app_error
}APP_Status_t;

typedef enum {
    APP_WAKEUP_STATES_SLEEP          = 0x00,
    APP_WAKEUP_STATES_STOP,
    APP_WAKEUP_STATES_RTC,
    APP_WAKEUP_STATES_3AXIS,
    APP_WAKEUP_STATES_TEMP_HUM,
} APP_STATE_t;

void app_update_adv_viberate_value(void);
void app_update_adv_tmp_hum_value(void);
void app_viberate_value_output(void);
void app_update_adv_tilt_angle(void);
void app_tilt_angle_output(void);

void app_excute_one_time_in_standby_mode(void);
void app_3axis_int_callback(void);
void app_wakeup_handle(void);
void app_wakeup_flag_set(uint8_t data);
uint8_t app_wakeup_flag_get(void);
/*flash*******************************************************************/

/*OTA*/
void app_get_firmware_version(uint8_t* data);
void app_ota_reset(void);
void app_file_rx(uint8_t* data, uint8_t len);
void app_crc_value(uint8_t data);
void app_write_firmware_version(uint8_t* data);
void app_fft_output(void);
void app_update_adv_fft_value(void);
void app_i2c_dma_rx_cmp_callback(uint8_t* data);
#endif //_APP_H_

